import { MomService } from './../../../@core/services/mom/mom.service';
import { Component, Input } from '@angular/core';
import { TableWidthConfig } from 'ng-devui';
import { DeviceService } from 'src/app/@core/services/device.ts/device.service';
@Component({
  selector: 'app-select-mom',
  templateUrl: './select-mom.component.html',
  styleUrls: ['./select-mom.component.scss']
})
export class SelectMOMComponent {
  @Input() data: any;
  isSelected = false;
  displayTableData: any[] = [];
  tableheight = '230px';
  selectData: any;
  searchName: ''
  pager = {
    total: 20,
    pageIndex: 1,
    pageSize: 20
  };
  pageSizeOptions = [10, 20, 30, 50, 100];
  dataTableOptions = {
    columns: [
      {
        field: 'radio',
        header: '选择',
        fieldType: 'radio',
        fixedLeft: '0px'
      },
      {
        field: 'type',
        header: '物料名称',
        fieldType: 'text'
      },
      {
        field: 'type',
        header: '物料编码',
        fieldType: 'text'
      },
      {
        field: '版本',
        header: '版本',
        fieldType: 'text'
      },
      {
        field: '工艺路线',
        header: '工艺路线',
        fieldType: 'text'
      },
      {
        field: '开始日期',
        header: '开始日期',
        fieldType: 'text'
      },
      {
        field: '结束日期',
        header: '结束日期',
        fieldType: 'text'
      }
    ]
  };
  tableWidthConfig: TableWidthConfig[] = [
    {
      field: 'radio',
      width: '50px'
    },
    {
      field: 'enabled',
      width: '150px'
    },
    {
      field: 'enabled',
      width: '150px'
    },
    {
      field: 'enabled',
      width: '150px'
    },
    {
      field: 'enabled',
      width: '150px'
    },
    {
      field: 'enabled',
      width: '150px'
    },
    {
      field: 'enabled',
      width: '150px'
    },
  ]
  constructor(private MomService: MomService) { }
  ngOnInit(): void {
    this.searchName = this.data.productNum
    this.MomService.GetMethodOfManufactures(this.searchName, this.pager.pageIndex, this.pager.pageSize, '已核准').subscribe((res: any) => {
      this.displayTableData = res.items
      this.pager.total = res.totalCount
    })
  }
  radio(event: any, rowItem: any) {
    if (event.target.checked) {
      this.isSelected = true;
      this.selectData = rowItem
    }
  }
  pageIndexChange($event: any) {
    this.pager.pageIndex = $event;
    this.MomService.GetMethodOfManufactures(this.searchName, this.pager.pageIndex, this.pager.pageSize).subscribe((res: any) => {
      this.displayTableData = res.items
      this.pager.total = res.totalCount
    })
  }//切换页码
  pageSizeChange($event: any) {
    this.MomService.GetMethodOfManufactures(this.searchName, this.pager.pageIndex, this.pager.pageSize).subscribe((res: any) => {
      this.displayTableData = res.items
      this.pager.total = res.totalCount
    })
  }//改变每页显示数量
  search() {
    this.MomService.GetMethodOfManufactures(this.searchName, this.pager.pageIndex, this.pager.pageSize).subscribe((res: any) => {
      this.displayTableData = res.items
      this.pager.total = res.totalCount
    })
  }
  reset() {
    this.searchName = ''
    this.MomService.GetMethodOfManufactures(this.searchName, this.pager.pageIndex, this.pager.pageSize).subscribe((res: any) => {
      this.displayTableData = res.items
      this.pager.total = res.totalCount
    })
  }
}
